package kr.ac.postech.marathon.server;

import javax.jdo.PersistenceManager;

import kr.ac.postech.marathon.client.RegistrationService;
import kr.ac.postech.marathon.client.models.Address;
import kr.ac.postech.marathon.client.models.Registration;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class RegistrationServiceImpl extends RemoteServiceServlet implements
		RegistrationService {

	public String register(Registration r) {
		
		if(r.getIdNum().isValid() == false) {
			return "Invalid Id number";
		}
		
		Address addr = r.getAddr();
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try{
			Entry entry = new Entry(r.getType(), 
					r.getName(), 
					r.getDept(), 
					addr.getZipCode1(), 
					addr.getZipCode2(), 
					addr.getAddress());
			pm.makePersistent(entry);
		} finally {
			pm.close();
		}
		
		return "Registration success";
	}

}
